package com.alison.module.author;

import com.alison.module.author.mapper.AuthorMapper;
import com.alison.module.author.mapper.SqlMapper;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @Author alison
 * @Date 2024/3/30 9:15
 * @Version 1.0
 * @Description
 */
@SpringBootApplication
//@MapperScan("com.alison.**.mapper")
@MapperScan("com.alison.module.author.mapper")
public class AuthorApplication implements ApplicationRunner {

    public static void main(String[] args) {
        SpringApplication.run(AuthorApplication.class);
    }

    @Autowired
    private AuthorMapper authorMapper;

    @Override
    public void run(ApplicationArguments args) throws Exception {
//        nativeSql();
    }

    private void authorTest() {
        authorMapper.selectByPrimaryKey(1);
        authorMapper.selectAllInIdsArr(new String[]{"1", "2"});
        authorMapper.selectAllInIdsSet(Sets.newHashSet(1, 2));
        authorMapper.selectAllInIdsList(Lists.newArrayList(1, 2));
        System.out.println("---------idsMap-----------");
        authorMapper.selectAllInIdsMap(ImmutableMap.of("ids", Lists.newArrayList(1, 2)));
    }

    @Autowired
    private SqlMapper sqlMapper;

    private void nativeSql() {
        String ddl = "create table if not exists user\n" + "(\n" + "    id   int auto_increment\n" + "        primary key,\n" + "    name varchar(1024) null,\n" + "    pwd  varchar(1024) null\n" + ")\n" + "    collate = utf8_general_ci;\n" + "\n";
        sqlMapper.nativeDDLSql(ddl);
    }
}
